//
//  WHEnterpriseCompanyCell.m
//  WHEasyBizLink
//
//  Created by shengmeng chen on 2024/11/29.
//

#import "WHEnterpriseCompanyCell.h"
#import "WHEnterpriseCompanyModel.h"
#import "UIView+Rounded.h"
#import "SDAutoLayout.h"
#import "myUILabel.h"

@interface WHEnterpriseCompanyCell ()

@property(nonatomic,strong)UIView*mbgView;

@property(nonatomic,strong)UIImageView*micon;

/** 单位类型 **/
@property (nonatomic, weak)UIButton*comTypeImg;

/** 公司名称  **/
@property (nonatomic, weak)UILabel*comNameLabel;

/** 联系人 **/
@property (nonatomic, weak)UILabel*contactNameTitle;
@property (nonatomic, weak)UILabel*contactNameLabel;

/** 联系电话 **/
@property (nonatomic, weak)UILabel*contactTellTitle;
@property (nonatomic, weak)UILabel*contactTellLabel;

/** 创建日期  **/
@property (nonatomic, weak)UILabel*creatDateTitle;
@property (nonatomic, weak)UILabel*creatDateLabel;

/** 企业地址  **/
@property (nonatomic, weak)UILabel*addresNameTitle;
@property (nonatomic, weak)myUILabel*addresNameLabel;

/** 分割线    **/
@property (nonatomic,weak)UIView*separatorLine;

@end

@implementation WHEnterpriseCompanyCell

-(void)createUIControls
{
    [super createUIControls];
    self.backgroundColor = [UIColor clearColor];
    _mbgView =[[UIView alloc] init];
    _mbgView.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:self.mbgView];
    [UIView setViewRoundedWithRad:10 byRoundingCorners:UIRectCornerAllCorners view:self.mbgView];
    
    _micon = [[UIImageView alloc] init];
    _micon.backgroundColor = [UIColor whiteColor];
    [_micon setViewRoundedShadowWithRad:10 byRoundingCorners:UIRectCornerAllCorners];
    [self.mbgView addSubview:self.micon];
    
    /**   单位类型  **/
    UIButton  *comTypeImg = [[UIButton alloc] init];
    [comTypeImg setTitle:@"企业" forState:UIControlStateNormal];
    comTypeImg.titleLabel.font = [UIFont systemFontOfSize:14];
    [comTypeImg setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [comTypeImg setBackgroundImage:[UIImage imageNamed:@"enterprise_type_select"] forState:UIControlStateNormal];
    [comTypeImg setBackgroundImage:[UIImage imageNamed:@"enterprise_type_default"] forState:UIControlStateSelected];
    [self.mbgView addSubview:comTypeImg];
    _comTypeImg = comTypeImg;
    
    /**  公司名称  **/
    UILabel*comNameLabel = [[UILabel alloc]init];
    comNameLabel.font = [UIFont systemFontOfSize:17*WidthScale>19?19:17*WidthScale];
    comNameLabel.textColor = [UIColor colorWithHexString:@"#1B6AC7" alpha:1.0];
    [self.mbgView addSubview:comNameLabel];
    comNameLabel.numberOfLines = 2;
    _comNameLabel = comNameLabel;
    
    /**   联系人  **/
    UILabel*contactNameTitle = [[UILabel alloc]init];
    contactNameTitle.font = [UIFont systemFontOfSize:15];
    contactNameTitle.textColor = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
    [self.mbgView addSubview:contactNameTitle];
    contactNameTitle.numberOfLines =0;
    contactNameTitle.text = @"联  系  人:";
    _contactNameTitle = contactNameTitle;
    
    UILabel*contactNameLabel = [[UILabel alloc]init];
    contactNameLabel.font = [UIFont systemFontOfSize:15];
    contactNameLabel.textColor = [UIColor colorWithHexString:@"#20335A" alpha:1.0];
    [self.mbgView addSubview:contactNameLabel];
    contactNameLabel.numberOfLines =0;
    contactNameLabel.text = @"";
    _contactNameLabel = contactNameLabel;
    
    /**   联系电话  **/
    UILabel*contactTellTitle = [[UILabel alloc]init];
    contactTellTitle.font = [UIFont systemFontOfSize:15];
    contactTellTitle.textColor = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
    [self.mbgView addSubview:contactTellTitle];
    contactTellTitle.numberOfLines =0;
    contactTellTitle.text = @"联系电话:";
    _contactTellTitle = contactTellTitle;
    
    UILabel*contactTellLabel = [[UILabel alloc]init];
    contactTellLabel.font = [UIFont systemFontOfSize:15];
    contactTellLabel.textColor = [UIColor colorWithHexString:@"#20335A" alpha:1.0];
    [self.mbgView addSubview:contactTellLabel];
    contactTellLabel.numberOfLines =0;
    contactTellLabel.text = @"";
    _contactTellLabel = contactTellLabel;
    
    /**   创建日期  **/
    UILabel*creatDateTitle = [[UILabel alloc]init];
    creatDateTitle.font = [UIFont systemFontOfSize:15];
    creatDateTitle.textColor = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
    [self.mbgView addSubview:creatDateTitle];
    creatDateTitle.numberOfLines =0;
    creatDateTitle.text = @"申报日期:";
    _creatDateTitle = creatDateTitle;
    
    UILabel*creatDateLabel = [[UILabel alloc]init];
    creatDateLabel.font = [UIFont systemFontOfSize:15];
    creatDateLabel.textColor = [UIColor colorWithHexString:@"#20335A" alpha:1.0];
    [self.mbgView addSubview:creatDateLabel];
    creatDateLabel.numberOfLines =0;
    creatDateLabel.text = @"";
    _creatDateLabel = creatDateLabel;
    
    /**   企业地址  **/
    UILabel*addresNameTitle = [[UILabel alloc]init];
    addresNameTitle.font = [UIFont systemFontOfSize:15];
    addresNameTitle.textColor = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
    [self.mbgView addSubview:addresNameTitle];
    addresNameTitle.numberOfLines = 2;
    addresNameTitle.text = @"单位地址:";
    _addresNameTitle = addresNameTitle;
    
    myUILabel*addresNameLabel = [[myUILabel alloc]init];
    addresNameLabel.font = [UIFont systemFontOfSize:15];
    addresNameLabel.textColor = [UIColor colorWithHexString:@"#20335A" alpha:1.0];
    [self.mbgView addSubview:addresNameLabel];
    addresNameLabel.numberOfLines = 2;
    [addresNameLabel setVerticalAlignment:VerticalAlignmentTop];
    addresNameLabel.text = @"";
    _addresNameLabel = addresNameLabel;
    
}

-(void)setUpUIControlsLayout
{
    [super setUpUIControlsLayout];
    
    _mbgView
    .sd_layout
    .topSpaceToView(self.contentView, 10)
    .bottomSpaceToView(self.contentView, 10)
    .leftSpaceToView(self.contentView, 15)
    .rightSpaceToView(self.contentView,15);

    _micon
    .sd_layout
    .topSpaceToView(self.mbgView, 5)
    .bottomSpaceToView(self.mbgView,5)
    .leftSpaceToView(self.mbgView, 5)
    .rightSpaceToView(self.mbgView,5);
    
    /**  公司名称  **/
    _comNameLabel
    .sd_layout
    .topSpaceToView(self.mbgView,kMarginH)
    .leftSpaceToView(self.mbgView,kMarginW*2+60)
    .rightSpaceToView(self.mbgView,kMarginW)
    .heightIs(50);
    
    /**  单位类型  **/
    _comTypeImg
    .sd_layout
    .leftSpaceToView(self.mbgView,kMarginW*2)
    .widthIs(50)
    .heightIs(25)
    .centerYEqualToView(self.comNameLabel);
    
    /**   联系人  **/
    _contactNameTitle
    .sd_layout
    .topSpaceToView(self.comNameLabel,5)
    .leftSpaceToView(self.mbgView,kMarginW*2)
    .widthIs(75)
    .heightIs(20);
    
    _contactNameLabel
    .sd_layout
    .topSpaceToView(self.comNameLabel,5)
    .leftSpaceToView(self.contactNameTitle,0)
    .rightSpaceToView(self.mbgView,kMarginW*2)
    .heightIs(20);
    
    /**   联系电话  **/
    _contactTellTitle
    .sd_layout
    .topSpaceToView(self.contactNameLabel,5)
    .leftSpaceToView(self.mbgView,kMarginW*2)
    .widthIs(75)
    .heightIs(20);
    
    _contactTellLabel
    .sd_layout
    .topSpaceToView(self.contactNameLabel,5)
    .leftSpaceToView(self.contactTellTitle,0)
    .rightSpaceToView(self.mbgView,kMarginW*2)
    .heightIs(20);
    
    /**   创建日期  **/
    _creatDateTitle
    .sd_layout
    .topSpaceToView(self.contactTellLabel,5)
    .leftSpaceToView(self.mbgView,kMarginW*2)
    .widthIs(75)
    .heightIs(20);
    
    _creatDateLabel
    .sd_layout
    .topSpaceToView(self.contactTellLabel,5)
    .leftSpaceToView(self.creatDateTitle,0)
    .rightSpaceToView(self.mbgView,kMarginW*2)
    .heightIs(20);
    
    /**   企业地址  **/
    _addresNameTitle
    .sd_layout
    .topSpaceToView(self.creatDateLabel,5)
    .leftSpaceToView(self.mbgView,kMarginW*2)
    .widthIs(75)
    .heightIs(20);
    
    _addresNameLabel
    .sd_layout
    .topSpaceToView(self.creatDateLabel,5)
    .leftSpaceToView(self.addresNameTitle,0)
    .rightSpaceToView(self.mbgView,kMarginW*2)
    .heightIs(40);
    
    [self setupAutoHeightWithBottomViewsArray:@[self.addresNameLabel] bottomMargin:kMarginH];
    [_mbgView setupAutoHeightWithBottomViewsArray:@[self.addresNameLabel] bottomMargin:0];
}

-(void)setModel:(WHEnterpriseCompanyModel *)model
{
    _model = model;
    
    _comNameLabel.text    = model.comname;
    NSString *title = model.comtypenm;
    if(model.comtypenm.length>2){
        title = [model.comtypenm substringWithRange:NSMakeRange(0,2)];
    }
    [_comTypeImg setTitle:title forState:UIControlStateNormal];
    /**   联系人  **/
    _contactNameLabel.text  =[NSString stringWithFormat:@"%@",model.linkuser];
    /**   联系电话  **/
    _contactTellLabel.text  =[NSString stringWithFormat:@"%@",model.linktel];
    /**   创建日期  **/
    _creatDateLabel.text  =[NSString stringWithFormat:@"%@",model.createddate];
    /**   企业地址  **/
    _addresNameLabel.text =[NSString stringWithFormat:@"%@",model.addr];
    
    if ([model.enable isEqualToString:@"1"]) {
        _comNameLabel.textColor    = [UIColor colorWithHexString:@"#1B6AC7" alpha:1.0];
        _contactNameLabel.textColor= [UIColor colorWithHexString:@"#20335A" alpha:1.0];
        _contactTellLabel.textColor= [UIColor colorWithHexString:@"#20335A" alpha:1.0];
        _creatDateLabel.textColor  = [UIColor colorWithHexString:@"#20335A" alpha:1.0];
        _addresNameLabel.textColor = [UIColor colorWithHexString:@"#20335A" alpha:1.0];
        _comTypeImg.selected = NO;
    }else
    {
        _comNameLabel.textColor    = [UIColor colorWithHexString:@"#8D8D8D" alpha:1.0];
        _contactNameLabel.textColor  = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
        _contactTellLabel.textColor  = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
        _creatDateLabel.textColor  = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
        _addresNameLabel.textColor = [UIColor colorWithHexString:@"#A1A1A1" alpha:1.0];
        _comTypeImg.selected = YES;
    }
    
}

@end
